import jsonp from "../API"


const actions={

    //???????
    
    loadSwiperData(store){
        // console.log(store)
        if(store.state.swiperImages.length===0){
            jsonp.loadData({
                appPlat: "m",
                pids: "51822"
            }).then(({ data, success }) => {
                if (success) {
                    store.commit("setSwiperImages",data[51822]["list"])
                } else {
                    console.log(data.msg);
                }
            });
        }
    },
    

    //????????

    loadClassificationData(store){
        // console.log(store)
        if(store.state.classificationImages.length===0){

            jsonp.loadData({
                appPlat: "m",
                pids: "106930"
            }).then(({ data, success }) => {
                if (success) {
                    store.commit("setClassificationImages",data[106930]["list"])
                } else {
                    console.log(data.msg);
                }
            });
        }
    },

    //????????

    loadBoonData(store){
        // console.log(store)
        if(store.state.boonImages.length===0){

            jsonp.loadData({
                appPlat: "m",
                pids: "51833"
            }).then(({ data, success }) => {
                if (success) {
                    // console.log(data[51833]["list"]);
                    store.commit("setBoonImages",data[51833]["list"])
                } else {
                    console.log(data.msg);
                }
            });
        }
    },


    loadHotTypeData(store){
        // console.log(store)
        if(store.state.hotTypeImages.length===0){

            jsonp.loadData({
                appPlat: "m",
                pids: "51836"
            }).then(({ data, success }) => {
                if (success) {
                    // console.log(data[51836]["list"]);
                    store.commit("setHotTypeImages",data[51836]["list"])
                } else {
                    console.log(data.msg);
                }
            });
        }
    },

    //??????????????

    loadGuessData({commit,state}){
        if(state.guessImages.length===0){
            jsonp.loadGuessData({
                pid:"9750",
                sort:"pop",
                cKey:46
            }).then(({success,result:{wall:{docs}}})=>{
                // console.log(docs);
                if(success){
                    commit("setGuessImages",docs);
                }else{
                    console.log(data.msg);
                }
            })
        }

    },

    loadClassLeftData({commit,state}){
        if(state.classifyLeftData.length===0){
            jsonp.loadClassifyLeftData({
                appPlat:"m",
                pids:41789
            }).then(({data,success})=>{
                if(success){
                    let list=data[41789]["list"]
                    commit("setClassifyLeftData",list);
                    commit("setChooseId",{maitKey:list[0].maitKey,miniWallkey:list[0].miniWallkey})
                }else{
                    console.log(data.msg);
                }
            })
        }
    },

    loadClassifyRightTopData({commit,state}){
        jsonp.loadClassifyRightTopData({
            appPlat:"m",
            pid:state.chooseId.maitKey
        }).then(({data,success})=>{
            if(success){
                // console.log(data);
                let bannerList=data.bannerHead?data.bannerHead.list:[];
                let list=data.categoryNavigation.list;
                // console.log("RightTopData",list)
                commit("setClassifyRTopBannerHead",bannerList);
                commit("setClassifyRTopImages",list);
            }else{
                console.log(data.msg);
            }
        })
    },

    loadClassifyRightDownData({commit,state}){
        jsonp.loadClassifyRightDownData({
            fcid:state.chooseId.miniWallkey,
            page:1,
            sort:state.sort,
            cKey:"h5-cube"
        }).then(({success,result})=>{
            if(success){
                let title=result.sortFilter;
                let list=result.wall.docs;
                // console.log(title,list);
                commit("setClassifyRDownTitle",title)
                commit("setClassifyRDownImages",list);
            }else{
                console.log(data.msg);
            }
        })
    },


    loadTopSearchData({commit,state}){
        jsonp.loadTopSearchData({
            platform:"H5",
            code:"hotWord,sketch"
        }).then(({success,data})=>{
            if(success){
                let frontword=data.sketch.data.frontword;
                let hotWord=data.hotWord.data
                commit("setSearchFrontword",frontword);
                commit("setSearchHotWord",hotWord);
            }else{
                console.log(data.msg);
            }
        })
    },




    
    loadGoodsShowData({commit,state},contents){
        jsonp.loadGoodsShowData({
            q:contents.q,
            cKey:46,
            page:1,
            sort:state.goodsSort
        }).then(({success,result})=>{
            if(success){
                let title=result.sortFilter;
                let list=result.wall.docs;
                // console.log(title,list);
                commit("setGoodsTypes",title)
                commit("setGoodsList",list);
            }else{
                console.log(data.msg);
            }
        })
    },

    loadTypeShowData({commit,state},contents){
        jsonp.loadGoodsShowData({
            fcid:contents.fcid,
            title:contents.title,
            cKey:16,
            page:1,
            sort:state.goodsSort
        }).then(({success,result})=>{
            if(success){
                let title=result.sortFilter;
                let list=result.wall.docs;
                // console.log(title,list);
                commit("setGoodsTypes",title)
                commit("setGoodsList",list);
            }else{
                console.log(data.msg);
            }
        })
    },



    loadGoodsCommentList({commit,state},contents){
        jsonp.loadGoodsCommentList({
            appAplat:"m",
            type:1,
            itemId:contents.itemId
        }).then(({success,data})=>{
            if(success){
                let list=data.list;
                let total=data.total;
                // console.log(list);
                commit("setGoodsCommentList",{list,total});
            }else{
                console.log(data.msg);
            }
        })
    },
}

export default actions;